const wxpay = require('../../utils/pay.js')
const WXAPI = require('../../wxapi/main')
var app = getApp();
const CONFIG = require('../../config.js')
const regeneratorRuntime = require('../../utils/runtime')
import imageUtil from '../../utils/image'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    refuserInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    const _this = this;
    const token = wx.getStorageSync('token');
    WXAPI.userRef(token).then(function (res) {
      _this.setData({
        refuserInfo: res.resultData.row
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  searchdoce: function(e) {
    let code = e.detail.value;
    if (code.length != 8) {
      return code;
    }
    const _this = this;
    WXAPI.userByCode(code).then(function (res) {
      _this.setData({
        refuserInfo: res.resultData.row
      })
    })
  },
  _toPayTap: function (orderId) {
    const _this = this
    wxpay.wxpay('vip', 0, orderId, "/pages/my/index");
  },
  bindSave: function (e) {
    const that = this;
    const code = e.detail.value.code;
    WXAPI.vipPay(code).then(function (res) {
      if (res.type == 'success') {
        let _row = res.resultData.row;
        let _msg = _row.remark;
        wx.showModal({
          title: '请确认支付',
          content: _msg,
          confirmText: "确认支付",
          cancelText: "取消支付",
          success: function (res) {
            console.log(res);
            if (res.confirm) {
              that._toPayTap(_row.id)
            } else {
              console.log('用户点击取消支付')
            }
          }
        });
      } else {
        wx.showModal({
          title: '错误',
          content: '无法获取用户资金信息',
          showCancel: false
        })
      }
    })
  }
})